#!/usr/bin/python
# -*- coding: utf-8 -*-
import maya.cmds as mc
import maya.mel as mel
import LZ_realistBodySys_commands
reload(LZ_realistBodySys_commands)
import LZ_realistBodySys_init
reload(LZ_realistBodySys_init)

'''
-------------------------------------------------------------------------------------

'''

"""
        #=====================================================      #
        #         Script Name: realistBodySys baseSetting_builder   #
        #         Author:   lizhi                                   #
        #         start date: Oct 31, 2014                          #
        #         start Updated: Oct 31, 2014                       #
        #         Update/Change this file at:                       #
        #         company: http://www.originalforce.com/            #
        #         Email:294596787@qq.com                            #
        # Please do not alter any information above this line       #
        #===========================================================#
        #                                                           
        #python                                                     #
        #directions (for use):                                      #
        #                                                           #
        #                                                           #
        #===========================================================#
        """   
class LZ_realistBodySys_baseSetting_builder(LZ_realistBodySys_commands.LZ_realistBodySys_commands , LZ_realistBodySys_init.LZ_realistBodySys_init):
    def __init__(self):
        LZ_realistBodySys_init.LZ_realistBodySys_init.__init__(self)

        #  spine 
        self.hip_JntTemple = self.centerPoint_hip[0]
        self.hipEnd_JntTemple = self.centerPoint_hipEnd[0]
        self.spine1_JntTemple = self.centerPoint_spine1[0]
        self.spine2_JntTemple = self.centerPoint_spine2[0]
        self.chest_JntTemple = self.centerPoint_chest[0]
        self.neck_JntTemple = self.centerPoint_neck[0]
        self.head_JntTemple = self.centerPoint_head[0]
        self.headEnd_JntTemple = self.centerPoint_headEnd[0]
        self.jaw_JntTemple = self.centerPoint_jaw[0]
        self.jawEnd_JntTemple = self.centerPoint_jawEnd[0]
        ##```````````````````````````````````````````````````````````````````
        #   arm 
        self.shoulder_JntTemple = self.L_centerPoint_shoulder[0]
        self.clavicle_JntTemple = self.L_centerPoint_clavicle[0]
        self.arm_JntTemple = self.L_centerPoint_arm[0]
        self.foreArm_JntTemple = self.L_centerPoint_foreArm[0]
        self.hand_JntTemple = self.L_centerPoint_hand[0]
        
        ##```````````````````````````````````````````````````````````````````
        #   leg
        self.upleg_JntTemple = self.L_centerPoint_upleg[0]
        self.leg_JntTemple = self.L_centerPoint_leg[0]
        self.foot_JntTemple = self.L_centerPoint_foot[0]
        self.toe_JntTemple = self.L_centerPoint_toe[0]
        self.toeend_JntTemple = self.L_centerPoint_toeend[0]
        
        self.inside_JntTemple = self.L_centerPoint_inside[0]
        self.outside_JntTemple = self.L_centerPoint_outside[0]
        self.toeDnEnd_JntTemple = self.L_centerPoint_toeDnEnd[0]
        self.reverseHeel_JntTemple = self.L_centerPoint_reverseHeel[0]
        
    def LZ_realistBodySys_baseSetting_globalGrp(self,charactorName = ''):
        
        allCtrl = 'all_ctrl'
        globalCtrl = 'global_ctrl'
        
        for ctrl in  [allCtrl,globalCtrl ]:
            mc.group(em=True,n = ctrl)
            self.creatControls_command( type = 5 ,curName = ctrl ,add=True )
            rotateHull=(0,0,0)
            transHuill = (0,0,0)
            scaleHull = (0,0,0)
            if 'all_' in ctrl :
                rotateHull = (0,0,0)
                transHuill=( 0, 0,0 )
                scaleHull = ( 50,50,50   )
            else:
                rotateHull = (0,0,0)
                transHuill=( 0 , 0 , 0 )
                scaleHull = ( 60,60,60   )
                
            self.rotateCurveHull( curveName = ctrl,rx = rotateHull[0],ry = rotateHull[1], rz = rotateHull[2] ,centerP =2 )
            self.scaleCurveHull( curvename = ctrl,scalX = scaleHull[0],scalY = scaleHull[1], scalZ = scaleHull[2])
            self.moveCurveHull(curveName = ctrl ,tx = transHuill[0],ty = transHuill[1], tz = transHuill[2] )
        
        zero_all = self.makeZeroGrpTwo( OrgObj = [allCtrl,globalCtrl],sufname='_zero',cenObj= '' , Mode= 0 ,type = 'group',ro =True)
        

        mc.parent( zero_all[0] , globalCtrl )
        
        ##  vis ctrl
        
        visCtrl = self.createVis(  charactor = charactorName )
        
        return  (allCtrl ,visCtrl)
        
    def createVis(self , charactor = '' ):
        textName = charactor
        if textName != '':
            ###create text
            tempObj = mc.textCurves(ch=False,f = 'Times New Roman|h-13|w400|c0',t = textName)[0]
            TextCurve = mc.ls('makeTextCurves*')
            mc.delete(TextCurve)
            mc.makeIdentity(tempObj,apply=True,t=True,r=True,s=True)

            
            allObj = mc.listRelatives(tempObj,ad=True)
            allObj.append(tempObj)
            shapeList = []
            for obj in allObj:
                if mc.nodeType( obj ) == 'nurbsCurve':
                    shapeList.append(obj)
                else:
                    pass

            
            all_ctrl = mc.group(em=True,n = 'visibility_ctrl')
            
            for i,shape in enumerate(shapeList):
                

                    
                    mc.parent(shape,all_ctrl,r=True,s=True)

                    mc.setAttr(shape+'.overrideEnabled',1)
                    mc.setAttr(shape+'.overrideColor',17)
            mc.delete(tempObj)


            ctrlShape = mc.listRelatives(all_ctrl,s=True)
            for i,s in enumerate(ctrlShape):
                mc.rename(s,all_ctrl+str(i+1)+'Shape')

            self.lockAttr( obj = all_ctrl,attr = ['tx','ty','tz','rx','ry','rz','sx','sy','sz','v'])
            

            mc.addAttr(all_ctrl,ln = 'JntVis',at = 'long',k=True,dv=1,min=0,max=1)
            mc.setAttr(all_ctrl+'.JntVis',k=False,cb=True)

            mc.addAttr(all_ctrl,ln = 'CtrlVis',at = 'long',k=True,dv=1,min=0,max=1)
            mc.setAttr(all_ctrl+'.CtrlVis',k=False,cb=True)

            mc.addAttr(all_ctrl,ln = 'mode',at = 'double',k=True,dv=0,min=0,max=10)
            mc.setAttr(all_ctrl+'.mode',k=False,cb=True)
            

            

            mc.addAttr(all_ctrl,ln = 'FaceMode',at = 'enum',en = 'High:Low',k=True)
            mc.setAttr(all_ctrl+'.FaceMode',k=False,cb=True)

            mc.addAttr(all_ctrl,ln = 'BodyMode',at = 'enum',en = 'High:Low',k=True)
            mc.setAttr(all_ctrl+'.BodyMode',k=False,cb=True)

            mc.addAttr(all_ctrl,ln = 'FacialPanel',at = 'enum',en = 'On:Off',k=True)
            mc.setAttr(all_ctrl+'.FacialPanel',k=False,cb=True)

            mc.addAttr(all_ctrl,ln = 'meshDisplayType',at = 'enum',en = 'Normal:Template:refrence',k=True)
            mc.setAttr(all_ctrl+'.meshDisplayType',k=False,cb=True)
            
            
            self.normalizeHull( curvename = all_ctrl )
            self.scaleCurveHull( curvename = all_ctrl ,scalX =5,scalY=5,scalZ=5)
            all_ctrlZero = str(all_ctrl)+'_zero'
            mc.group(all_ctrl,n= all_ctrlZero )
            mc.setAttr( str(all_ctrlZero)+'.translateY',200)
        else:
            all_ctrlZero = ''
        return all_ctrlZero
    
    def LZ_realistBodySys_baseSetting_Spine(self):
        ctrlJnt_all = []
        skinJnt_all = []
        spineTemple = [self.hip_JntTemple,self.spine1_JntTemple,self.spine2_JntTemple,self.chest_JntTemple,self.neck_JntTemple,self.head_JntTemple,self.headEnd_JntTemple]
        for st in spineTemple:
            skeleton = str(st).replace('_Temple','_skeleton')
            
            
            PreJntame = str(skeleton).replace('_skeleton','_jnt')
            
            
            jntName = self.deletePreName(oriName = PreJntame ,deletePre = 'Rbs_')
            skinJnt = str(jntName).replace('_jnt' , '_skinJnt')
            
            self.LZ_creatJoint( skeleton, jntName )
            ctrlJnt_all.append( jntName )
            
            
            mc.duplicate( jntName , n = skinJnt)
            skinJnt_all.append(skinJnt)
            mc.setAttr(str(skinJnt)+'.v',0)
            
            
            mc.parentConstraint(jntName , skinJnt)
        
        self.sequenceParent(ctrlJnt_all[::-1])
        self.sequenceParent(skinJnt_all[::-1])
        
        
        
        self.makeZeroGrpTwo( OrgObj = ctrlJnt_all [:-1],sufname='mcap',cenObj='',Mode=1,type = 'joint',ro =True)
        ctrl_all = self.makeZeroGrpTwo( OrgObj = ctrlJnt_all [:-1],sufname='ctrl',cenObj='',Mode=1,type = 'joint',ro =True)
        
        for c_l in ctrl_all:
            self.creatControls_command( type = 5 ,curName = c_l ,add=True )
            self.rotateCurveHull( curveName = c_l,rx = 0,ry = 0, rz = 90 )
            self.scaleCurveHull( curvename = c_l,scalX = 10,scalY = 10, scalZ = 10 )
        
        
        
        
        #`````````````````````````````````````````````````````````````````
        hipSkeleton = ['Rbs_hip_Dn_skeleton','Rbs_hipEnd_skeleton']
        
        hip_dn_ajnt_all = []
        for hs in hipSkeleton:
        
            PreJntame = str(hs).replace('_skeleton','_jnt')
            
            
            jntName = self.deletePreName(oriName = PreJntame ,deletePre = 'Rbs_')
            
            self.LZ_creatJoint( hs, jntName )
            hip_dn_ajnt_all.append( jntName )
            if 'End' in hs:
                
                skinName =  str(jntName).replace('_jnt' , '_skinJnt')
                self.LZ_creatJoint( hs, skinName )
                mc.parentConstraint( jntName, skinName )
                mc.parent( skinName , skinJnt_all[-1])
                skinJnt_all.append( skinName )
            else:
                hip_dn_mcap = self.makeZeroGrpTwo( OrgObj = [jntName],sufname='mcap',cenObj='',Mode=1,type = 'joint',ro =True)[0]
                ctrl_jnt = self.makeZeroGrpTwo( OrgObj = [jntName],sufname='ctrl',cenObj='',Mode=1,type = 'joint',ro =True)[0]
                
                self.creatControls_command( type = 5 ,curName = ctrl_jnt ,add=True )
                self.rotateCurveHull( curveName = ctrl_jnt,rx = 0,ry = 0, rz = 90 )
                self.scaleCurveHull( curvename = ctrl_jnt,scalX = 8,scalY = 8, scalZ = 8 )

            #
        self.sequenceParent(hip_dn_ajnt_all[::-1])
        mc.parent( hip_dn_mcap, ctrlJnt_all[0])

        return([ctrlJnt_all,skinJnt_all])
        
    '''
        =========================================================
        ||                                                     ||
        ||胳膊 基础骨骼创建                                    ||
        ||the  base builder of arm                             ||
        ||                                                     ||
        =========================================================
        '''
        
    def LZ_realistBodySys_baseSetting_Arm(self,armSkeleton = ['Rbs_L_arm_skeleton','Rbs_L_foreArm_skeleton','Rbs_L_hand_skeleton'] , clavicle = 'Rbs_L_clavicle_skeleton',ctrlOrientReference = 'Rbs_L_hand_skeleton'):
        ctrlJnt_all = []
        drvJnt_all = []
        
        FKjnt_all = []
        IkJnt_all = []
        
        FK_Follow_all = []
        IK_follow_all = []
        
        '''
        
        
        
        
        '''
        
        NoPre_skeleton = self.deletePreName(oriName = armSkeleton[0] ,deletePre = 'Rbs_')
        Switch_ctrl = NoPre_skeleton.replace( '_skeleton' ,'_switch_ctrl')
        
        self.creatControls_command( type = 8 ,curName = Switch_ctrl ,add=False )
        self.scaleCurveHull( curvename = Switch_ctrl,scalX = 0.5,scalY = 0.5, scalZ = 0.5 )
        
        zero_switch_ctrl = self.makeZeroGrpTwo( OrgObj = [Switch_ctrl],sufname='_zero',cenObj='',Mode= 0 ,type = 'group',ro =True)[0]
        
        self.lockAttr( obj = Switch_ctrl ,attr =['tx','ty','tz','rx','ry','rz','sx','sy','sz','v'] )
        
        self.FG_addAttrs( objname=[ Switch_ctrl ],attrname='ik_fk_switch',dv=0,key=1,minValue=0,maxValue=1)
        
        '''
        
        
        
        
        '''
        
        armTemple = armSkeleton
        for at  in armTemple:
            skeleton = str(at).replace('_Temple','_skeleton')
            
            
            PreJntame = str(skeleton).replace('_skeleton','_jnt')
            
            
            jntName = self.deletePreName(oriName = PreJntame ,deletePre = 'Rbs_')
            drvJnt = str(jntName).replace('_jnt' , '_drv')
            
            FKjnt = str(jntName).replace('_jnt' , '_FKJnt')
            
            IkJnt = str(jntName).replace('_jnt' , '_IKJnt')
            
            Fk_follow = str(drvJnt).replace( '_drv','_FK_con')
            FK_Follow_all.append( Fk_follow )
            
            
            Ik_follow = str(drvJnt).replace( '_drv','_IK_con')
            IK_follow_all.append( Ik_follow )
            
            
            
            self.LZ_creatJoint( skeleton, jntName )
            ctrlJnt_all.append( jntName )
            
            
            mc.duplicate( jntName , n = drvJnt)
            drvJnt_all.append(drvJnt)
            
            mc.duplicate( jntName , n = FKjnt)
            FKjnt_all.append(FKjnt)
            
            mc.duplicate( jntName , n = IkJnt)
            IkJnt_all.append(IkJnt)
            
            for follow  in [ Fk_follow , Ik_follow ]:
                mc.group(em=True , n = follow )
                
                mc.parent( follow , drvJnt )
                self.clear_channelBox_Transform( obj= follow )
                
                if '_FK_' in follow:
                    #mc.parent(follow ,FKjnt )
                    mc.orientConstraint( FKjnt , follow )
                    
                elif '_IK_' in follow:
                    #mc.parent(follow ,IkJnt )
                    mc.orientConstraint( IkJnt , follow )
                mc.parent(follow , w=True)
            constraintNode = mc.orientConstraint(Fk_follow,Ik_follow,jntName)[0]
            
            
            mc.parentConstraint (jntName , drvJnt)
            
            ####  SDK  jnt constraint 
            #````````````````````````````````````````````````````````````
            
            driverAttribute = str( Switch_ctrl ) + '.ik_fk_switch'
            drivenAttribute_FK =  str( constraintNode ) + '.' + str( Fk_follow ) +'W0'
            drivenAttribute_IK =  str( constraintNode ) + '.' + str( Ik_follow ) +'W1'
            
            self.setDrivenKey(driverAttr = driverAttribute ,drivenAttr = drivenAttribute_FK ,driverV = 0 ,drivenV = 0 )
            self.setDrivenKey(driverAttr = driverAttribute ,drivenAttr = drivenAttribute_IK ,driverV = 0 ,drivenV = 1 )
            
            self.setDrivenKey(driverAttr = driverAttribute ,drivenAttr = drivenAttribute_FK ,driverV = 1 ,drivenV = 1 )
            self.setDrivenKey(driverAttr = driverAttribute ,drivenAttr = drivenAttribute_IK ,driverV = 1 ,drivenV = 0 )
            
    
        self.sequenceParent(ctrlJnt_all[::-1])
        self.sequenceParent(drvJnt_all[::-1])
        
        self.sequenceParent(FKjnt_all[::-1])
        self.sequenceParent(IkJnt_all[::-1])
        
        self.sequenceParent(IK_follow_all[::-1])
        self.sequenceParent(FK_Follow_all[::-1])
        
        armGroup = str(jntName ) + '_grp'
        
        
        mc.group(em=True,n= armGroup )
        mc.parentConstraint(clavicle,armGroup,mo=False ,n='needdeleteConstraint')
        mc.delete('needdeleteConstraint')
        
        mc.parent( ctrlJnt_all[0],drvJnt_all[0],FKjnt_all[0], IkJnt_all[0] ,IK_follow_all[0] ,FK_Follow_all[0] ,armGroup )
        
        self.makeZeroGrpTwo( OrgObj = FK_Follow_all + IK_follow_all + ctrlJnt_all,sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
        
        ######     FK  
        
        self.makeZeroGrpTwo( OrgObj = FKjnt_all ,sufname='mcap',cenObj='',Mode=1,type = 'joint',ro =True)
        
        FK_ctrl_all = self.makeZeroGrpTwo( OrgObj = FKjnt_all[0:-1] ,sufname='ctrl',cenObj= '' ,Mode=1,type = 'joint',ro =True)
        FK_ctrl = self.makeZeroGrpTwo( OrgObj = [FKjnt_all[-1] ],sufname='ctrl',cenObj= ctrlOrientReference ,Mode=1,type = 'joint',ro =True)[0]
        FK_ctrl_all.append(FK_ctrl)
        
        
        for fk_al in FK_ctrl_all:
            self.creatControls_command( type = 5 ,curName = fk_al ,add=True )
            self.rotateCurveHull( curveName = fk_al,rx = 0,ry = 0, rz = 90 )
            self.scaleCurveHull( curvename = fk_al,scalX = 5,scalY = 5, scalZ = 5 )
            
        #####    IK
        ikHandleName = str(IkJnt_all[0])+'_ikHandle'
        mc.ikHandle(startJoint = IkJnt_all[0] , endEffector = IkJnt_all[-1] ,solver = 'ikRPsolver',n  = ikHandleName)
        
        ikCtrl_name = str(IkJnt_all[-1]).replace('_IKJnt','_ik_ctrl')
        self.LZ_creatJoint( ctrlOrientReference , ikCtrl_name ) 
        #self.LZ_creatJoint( IkJnt_all[-1], ikCtrl_name )
        
        ikZerogrp = self.makeZeroGrpTwo( OrgObj = [ikCtrl_name],sufname='_zero',cenObj = '' ,Mode=0,type = 'group',ro =False)[0]
        mc.parent(ikZerogrp, armGroup )
        
        
        self.creatControls_command( type = 2 ,curName = ikCtrl_name ,add=True )
        self.rotateCurveHull( curveName = ikCtrl_name,rx = 0,ry = 0, rz = 90 )
        self.scaleCurveHull( curvename = ikCtrl_name,scalX = 10,scalY = 10, scalZ = 10 )
        
        mc.parent(ikHandleName,ikCtrl_name)
        
        
        '''     ----------------------    poleVector   ----------------------------    '''
        
        temple_vectorLoc = str(IkJnt_all[-1]).replace('_IKJnt','_poleVector_TempleLoc')

        
        self.getPoleVector(ikhandle = ikHandleName,locatorTemple = temple_vectorLoc )
        vector_zeroGrpTemple = self.makeZeroGrpTwo( OrgObj = [temple_vectorLoc],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)[0]
        
        mc.setAttr(str(temple_vectorLoc)+'.ty',60)
        mc.setAttr(str(temple_vectorLoc)+'.v',0)
        #if 'L_' in temple_vectorLoc:
        #    mc.setAttr(str(temple_vectorLoc)+'.ty',60)
        #elif 'R_' in temple_vectorLoc:
        #    mc.setAttr(str(temple_vectorLoc)+'.ty',-60)
        #
        Vector_zeroGrp = self.makeZeroGrpTwo( OrgObj = [temple_vectorLoc],sufname='ctrl_zero',cenObj='',Mode=1,type = 'group',ro =True)[0]
        poleVector_ctrl= self.makeZeroGrpTwo( OrgObj = [temple_vectorLoc],sufname='ctrl',cenObj='',Mode=1,type = 'group',ro =True)[0]
        
        self.creatControls_command( type = 7 ,curName = poleVector_ctrl ,add=True)
        self.scaleCurveHull( curvename = poleVector_ctrl,scalX = 3,scalY = 3, scalZ = 3 )
        mc.parent(Vector_zeroGrp , armGroup )
        
        mc.delete(vector_zeroGrpTemple)
        
        
        
        mc.poleVectorConstraint(temple_vectorLoc,ikHandleName)
        
        '''
        =========================================================
        ||                                                     ||
        ||nonroll 骨骼                                         ||
        ||the  joint of nonroll                                ||
        ||                                                     ||
        =========================================================
        '''
        
        for asl in range(len(ctrlJnt_all) - 1 ):
        
            parentObj = mc.listRelatives( ctrlJnt_all[asl] , p=True )[0]
            
            self.createNonroll_jnt(  startJnt = ctrlJnt_all[asl] ,endEffctor = ctrlJnt_all[asl+1] , parentObj = parentObj  ,followObj = ctrlJnt_all[asl] )

        
        '''
        =========================================================
        ||                                                     ||
        ||halfRotate 骨骼                                      ||
        ||the  joint of halfRotate                             ||
        ||                                                     ||
        =========================================================
        '''
        self.createHalfRotate_jnt( oriObj = drvJnt_all[1] )
        
        
        
        dirPosNeg = 1
        partPosNeg = 1
        
        #if ('arm' in zero_switch_ctrl)  or ('Arm' in zero_switch_ctrl):
        #    dirPosNeg = -1
        #elif 'leg' in zero_switch_ctrl:
        #    dirPosNeg = 1
        if 'R_'  in zero_switch_ctrl:
            partPosNeg = -1
        elif 'L_'  in zero_switch_ctrl :
            partPosNeg = 1
        
        PosNeg = dirPosNeg * partPosNeg
        
        mc.parent( zero_switch_ctrl , drvJnt )
        self.clear_channelBox_Transform( zero_switch_ctrl )
        
        
        mc.setAttr( str(zero_switch_ctrl)+'.' + 'ty' , PosNeg*10 )
        
        
        return armGroup
        
    def LZ_realistBodySys_baseSetting_clavicle(self,clavicleSkeleton = [ 'Rbs_L_shoulder_skeleton','Rbs_L_clavicle_skeleton','Rbs_L_arm_skeleton' ] , centergrp = 'Rbs_chest_skeleton'):
        
        
        
        
        nonPre_Skeleton_all = []
        for cs in clavicleSkeleton:
            NoPre_skeleton = self.deletePreName(oriName = cs ,deletePre = 'Rbs_')
            
            nonPre_Skeleton_all.append( NoPre_skeleton )
            
        clavicle_all_grp = nonPre_Skeleton_all[0].replace('_skeleton','_grp')
        mc.group( em =True ,n = clavicle_all_grp )
        mc.parent(clavicle_all_grp,centergrp)
        self.clear_channelBox_Transform( obj=  clavicle_all_grp )
        
        mc.parent(clavicle_all_grp,world =True)
        
        ##   create base jnt 
        clavicleJnt = str(nonPre_Skeleton_all[1]).replace('_skeleton','_jnt')
        clavicleJntEnd = str(nonPre_Skeleton_all[1]).replace('_skeleton','_jntEnd')
        
        clavicleJnt_all = [clavicleJnt,clavicleJntEnd]
        
        clavicleCtrl = str(nonPre_Skeleton_all[1]).replace('_skeleton','_Ctrljnt')
        clavicleCtrlEnd = str(nonPre_Skeleton_all[1]).replace('_skeleton','_CtrljntEnd')
        
        clavicleCtrl_all = [clavicleCtrl,clavicleCtrlEnd]
        
        
        claviclePoint = [ clavicleSkeleton[1] ,clavicleSkeleton[2] ]
        
        shoulderJnt = str(nonPre_Skeleton_all[0]).replace('_skeleton','_jnt')
        shoulderJntEnd = str(nonPre_Skeleton_all[0]).replace('_skeleton','_jntEnd')
        
        shoulderJnt_all = [shoulderJnt,shoulderJntEnd]

        
        shoulderPoint = [ clavicleSkeleton[0] ,clavicleSkeleton[2] ]
        
        for num in range(2):
        
            self.LZ_creatJoint( claviclePoint[num] , clavicleJnt_all[num] )
            
            self.LZ_creatJoint( shoulderPoint[num] , clavicleCtrl_all[num] )
            
            self.LZ_creatJoint( shoulderPoint[num] , shoulderJnt_all[num] )
    
        mc.parent( clavicleJnt_all[1] ,clavicleJnt_all[0] )
        mc.parent( shoulderJnt_all[1] ,shoulderJnt_all[0] )
        mc.parent( clavicleCtrl_all[1] ,clavicleCtrl_all[0] )
        
        ##  ikhandle 
        ikhandleName = str(clavicleJnt_all[0]) + '_ikhandle'
        pointLocName = str( ikhandleName ) + '_pointLoc'
        
        shoulderIkhandleName = str(shoulderJnt_all[0]) + '_ikhandle'
        shoulderPointLocName = str( shoulderIkhandleName ) + '_pointLoc'
        #
        mc.ikHandle( sj = clavicleJnt_all[0], ee =clavicleJnt_all[1] , n = ikhandleName )
        mc.ikHandle( sj = shoulderJnt_all[0], ee =shoulderJnt_all[1] , n = shoulderIkhandleName )
        #
        mc.group(em= True, n = pointLocName ) 
        mc.group(em= True, n = shoulderPointLocName ) 
        #
        mc.parent( pointLocName , ikhandleName )
        self.clear_channelBox_Transform( obj=  pointLocName )
        
        mc.parent( shoulderPointLocName , shoulderIkhandleName )
        self.clear_channelBox_Transform( obj=  shoulderPointLocName )
        
        
        #
        mc.parent( pointLocName ,shoulderJnt_all[0])
        mc.parent( shoulderPointLocName ,clavicleCtrl_all[0])
        
        
        mc.pointConstraint( pointLocName, ikhandleName  )
        mc.pointConstraint( shoulderPointLocName, shoulderIkhandleName  )

        mc.parent(  clavicleJnt_all[0] ,clavicle_all_grp)
        mc.parent(  clavicleCtrl_all[0] ,clavicle_all_grp)
        mc.parent(  shoulderJnt_all[0] ,clavicle_all_grp)
        mc.parent(  ikhandleName ,clavicle_all_grp)
        mc.parent(  shoulderIkhandleName ,clavicle_all_grp)
        
        ####

        self.makeZeroGrpTwo( OrgObj = [clavicleCtrl_all[0]],sufname='mcap',cenObj= '' , Mode=1,type = 'joint',ro =True)[0]
        clavicle_ctrls = self.makeZeroGrpTwo( OrgObj = [clavicleCtrl_all[0]],sufname='ctrl',cenObj= '' , Mode=1,type = 'group',ro =True)
        
        
        '''
        =========================================================
        ||                                                     ||
        ||创建控制器                                           ||
        ||create controller                                    ||
        ||                                                     ||
        =========================================================
        '''
        
        for cc_a in clavicle_ctrls:

            self.creatControls_command( type = 13 ,curName = cc_a ,add=True )
            rotateHull=(0,0,0)
            transHuill = (2.5,5,0)
            if 'R_' in cc_a:
                rotateHull = (0,0,180)
                transHuill=( transHuill[0] *-1 , transHuill[1]*-1 ,transHuill[2] )
            self.rotateCurveHull( curveName = cc_a,rx = rotateHull[0],ry = rotateHull[1], rz = rotateHull[2] ,centerP =2 )
            self.scaleCurveHull( curvename = cc_a,scalX = 2.5,scalY = 2.5, scalZ = 2.5)
            self.moveCurveHull(curveName = cc_a ,tx = transHuill[0],ty = transHuill[1], tz = transHuill[2] )
        
        
        return clavicle_all_grp
        
    def createHalfRotate_jnt(self,oriObj = '' ):
        halfJnt = str( oriObj )+'_half'
        halfJntDrv = str( oriObj )+'_half_drv'
        
        
        self.LZ_creatJoint( oriObj , halfJnt )
        
        self.LZ_creatJoint( oriObj , halfJntDrv )
        
        md_half = str(halfJnt)+ '_md' 
        
        mc.parent( halfJntDrv , halfJnt )
        
        dirPosNeg = 1
        partPosNeg = 1
        
        if ('arm' in oriObj)  or ('Arm' in oriObj):
            dirPosNeg = -1
        elif 'leg' in oriObj:
            dirPosNeg = 1
        if 'R_'  in oriObj:
            partPosNeg = -1
        elif 'L_'  in oriObj :
            partPosNeg = 1
        
        PosNeg = dirPosNeg * partPosNeg

        
        mc.setAttr(str(halfJntDrv)+'.tz' , PosNeg * 2 )
        mc.parent( halfJnt , oriObj)
        
        mc.createNode('multiplyDivide',n = md_half )
        
        mc.connectAttr( str(oriObj)+'.rotate', str(md_half)+'.input1' )
        
        mc.setAttr( str(md_half)+'.input2X' , -0.5)
        mc.setAttr( str(md_half)+'.input2Y' , -0.5)
        mc.setAttr( str(md_half)+'.input2Z' , -0.5)
        
        mc.connectAttr( str(md_half)+'.output' , str(halfJnt)+'.rotate' )
        
    def LZ_createRibbon_IKSpline(self,startObj ='' , endObj = '' , subdivison = 4 ):
        trans_start = mc.xform( startObj ,q=True , t=True,ws=True )
        trans_end = mc.xform( startObj ,q=True , t=True,ws=True )
        IK_curveName = str(startObj)+ '_Ribon_curve'
        
        print( trans_start )
        self.createStraightLine(curvename = IK_curveName , LocationInfo = [(trans_start[0] ,trans_start[1],trans_start[2]) ,(trans_end[0] ,trans_end[1],trans_end[2]) ]  )
        mc.rebuildCurve( IK_curveName , ch =False , rpo =1 ,rt =1,kr=0,kcp=1,kt=0,s=3,d=3,tol=0.01)
        
